package com.ostrich.library_logger.logger

import android.util.Log
import com.ostrich.library_log.LoggerLevel


/**
 * @Author : yaotianxue
 * @Time : On 2023/10/20 10:21
 * @Description : LogCatLogger:打印输出在logcat中
 */
class LogCatLogger: ILogger {
    private var isDebug: Boolean = true
    private var tag:String = ""
    private var level: LoggerLevel = LoggerLevel.Debug
    private var url: String = ""
    private var loggerFormat = "(:============>$tag %s ----->%s)" //格式化字符串  %s代表占位符
    override fun d(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Debug.ordinal){
            Log.d(this.tag,String.format(loggerFormat,tag,log))
        }
    }

    override fun v(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Verbose.ordinal){
            Log.d(this.tag,String.format(loggerFormat,tag,log))
        }
    }

    override fun i(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Info.ordinal){
            Log.d(this.tag,String.format(loggerFormat,tag,log))
        }
    }

    override fun w(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Warn.ordinal){
            Log.d(this.tag,String.format(loggerFormat,tag,log))
        }
    }

    override fun e(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Error.ordinal){
            Log.d(this.tag,String.format(loggerFormat,tag,log))
        }
    }


    override fun setDebug(isDebug: Boolean) {
        this.isDebug = isDebug
    }

    override fun setLogTag(TAG: String) {
        this.tag = TAG
    }

    override fun setLoggerLevel(level: LoggerLevel) {
        this.level = level
    }

    override fun setSaveUrl(url: String) {
        this.url = url
    }
}